/**
   Copyright 2012 FiveFai Lab

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
**/

package com.ff55.testbingo;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Main extends Activity {
	private TextView _nextNum;
	private ArrayList<Integer> _historical = new ArrayList<Integer>();
	private TextView _hisNum;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button b = (Button) findViewById(R.id.btn);
        b.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Main.this.pickNumber();
			}
		});

        _nextNum = (TextView) findViewById(R.id.nextNum);
        _hisNum = (TextView) findViewById(R.id.historical);
    }
    
    private void pickNumber() {
		int i = Integer.parseInt(Long.toString(Math.round(Math.random() * 123456 / Math.random() / 9430) % 75 + 1));
		
    	if (_historical.contains(i)) {
    		_nextNum.setText("XX");
    	} else {
    		_historical.add(i);
    		_nextNum.setText(Integer.toString(i));
    		if (_historical.size() % 5 == 0)
        		_hisNum.append("\n"+Integer.toString(i));
    		else
    			_hisNum.append("   "+Integer.toString(i));
    	}
    }
}